import 'package:flutter/material.dart';

import '../util/CacheUtil.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  late int _count = 0;

  @override
  void initState() {
    super.initState();
    _loadCacheData();
  }

  Future<void> _loadCacheData() async {
    String? cachedString = await CacheUtil.instance.getString('greeting');
    setState(() {
     if(cachedString != null){
       _count = int.parse(cachedString);
     }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: OutlinedButton(onPressed:  () async {
        /*context.push('/page1',extra: {
          "id":"1",
          "name":'哈哈哈'
        });*/
        _count = _count+1;
        setState((){

        });
        await CacheUtil.instance.setString('greeting', "${_count}");
      }, child: Text("HomePage: ${_count}")),
    );
  }
}
